package com.wbc.smartHome.dao;

import com.wbc.smartHome.model.Admin;
import com.wbc.smartHome.model.Menu;
import com.wbc.smartHome.model.SearchAdmin;
import com.wbc.smartHome.model.UpdatePasswordAdmin;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminDao {


    List<Admin> adminList(SearchAdmin searchAdmin);

    @Select("select id,name from menu where type = 2")
    List<Menu> menus();

    void insertAdmin(Admin admin);

    @Insert("insert into admin_menu(menuid,adminid)values(#{menuid},#{adminid})")
    void insertAdminMenu(@Param("menuid") Integer menuId,@Param("adminid") int id);

    @Delete("delete from admin_menu where adminid = #{adminid}")
    void deleteAdminMenu(@Param("adminid") int id);

    @Delete("delete from admin where id = #{id}")
    void deleteAdmin(int id);

/*    @Select("select id,account,phone from admin where id = #{id}")
    Admin getAdminById(int id);*/
    Admin getAdminById(int id);



/*    @Select("select menuid from admin_menu where id = #{id}")
    Integer[] getMenuIdsById(int id);*/

    @Update("update admin set account = #{account},phone = #{phone} ,adminid=#{admin.id},oper_time = now() where id = #{id}")
    void updataAdmin(Admin admin);

    @Select("select id, account from admin where account  = #{account}")
    Admin getAdminByAccount(String account);

    @Select("select password from admin where id = #{id}")
    Admin getPasswordById(Integer id);

    @Update("update admin set password = #{password},adminid=#{admin.id},oper_time = now() where id = #{id}")
    void updatePassword(UpdatePasswordAdmin updatePasswordAdmin);
}
